#include <iostream>
#include <thread>
using namespace std;

const std::string GetCurrentSystemTime()
{
	time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
	struct tm* ptm = localtime(&t);
	char date[64] = { 0 };
	sprintf(date, "%d-%02d-%02d %02d:%02d:%02d",
		(int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday,
		(int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec);
	return move(std::string(date));
}

void func()
{
	for (int i = 0; i < 5; i++)
	{
		//获取当前时间点
		auto NewTime = chrono::system_clock::now();
		//时间间隔
		chrono::seconds sec(3);
		//当前时间点后休眠3秒
		this_thread::sleep_until(NewTime + sec);
		cout << "子进程ID: " << this_thread::get_id() <<" "<< GetCurrentSystemTime() << endl;
	}
}

int main()
{
	thread t(func);
	// t.join();
    t.detach();
    cout<<" 我结束了~\n"<<endl;
	return 0;
}
